package com.yogee.topseller.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yogee.topseller.R;
import com.yogee.topseller.activity.login.model.bean.InterestLabelBean;
import com.yogee.topseller.bean.AddFastQueryBean;
import com.yogee.topseller.view.FlowLayout;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/21.
 */

public class AllLabelAdapter extends RecyclerView.Adapter<AllLabelAdapter.LabelViewHolder>{
    //上下文
    Context mContext;
    //标签数据
    List<AddFastQueryBean.FootListBeanNew> mLabelDatas;
    //已选中的标签
    public ArrayList<TextView> mSelectView = new ArrayList<>();
    private List<AddFastQueryBean.LabelListBean> labelListBeen = new ArrayList<>();

    private ArrayList<AddFastQueryBean.FootListBean> mSelectBean = new ArrayList<>();

    private FlowLayout.OnAddClickListener onAddClickListener;

    public AllLabelAdapter(Context context, FlowLayout.OnAddClickListener onAddClickListener) {
        this.mContext = context;
        this.onAddClickListener = onAddClickListener;
    }

    public void addData(List<AddFastQueryBean.FootListBeanNew> mLabelDatas, List<AddFastQueryBean.LabelListBean> mLabelListBean) {
        this.mLabelDatas = new ArrayList<>();
        this.mLabelDatas = mLabelDatas;
        this.labelListBeen = mLabelListBean;
        notifyDataSetChanged();
    }


    @Override
    public void onBindViewHolder(final LabelViewHolder holder, final int position) {
        holder.tv_more.setVisibility(View.GONE);
        holder.mLabelType.setText(mLabelDatas.get(position).getType());
        holder.mLabelData.setOnAddClickListener(onAddClickListener);
        holder.mLabelData.setHotDatasShow2(mLabelDatas.get(position).getTypeList(),labelListBeen);

//        holder.mLabelData.setOnTagClickListener(new FlowLayout.OnTagClickListener() {
//            @Override
//            public void TagClick(InterestLabelBean.ListBean.LabelListBean bean, TextView textView) {
////                mSelectBean.add(bean);
//                textView.setTextColor(mContext.getResources().getColor(R.color.white));
//                textView.setBackgroundResource(R.drawable.corens_100_style_select_new);
//
//                if (!mSelectView.contains(textView)) {
//                    mSelectView.add(textView);
//
//                } else {
//                    if (mSelectBean.contains(bean)) {
//                        mSelectBean.remove(bean);
//                    }
//                    textView.setBackgroundResource(R.drawable.corens_100_style_unselect);
//                    textView.setTextColor(Color.parseColor("#4a4a4a"));
//                    mSelectView.remove(textView);
//                }
//            }
//        });
    }

    @Override
    public LabelViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        item_interest_label
        LabelViewHolder holder = new LabelViewHolder(LayoutInflater.from(
                mContext).inflate(R.layout.item_interest_label_register, parent,
                false));
        return holder;
    }

    @Override
    public int getItemCount() {
        return mLabelDatas == null ? 0 : mLabelDatas.size();
    }



    class LabelViewHolder extends RecyclerView.ViewHolder {

        TextView mLabelType,tv_more;
        FlowLayout mLabelData;


        public LabelViewHolder(View view) {
            super(view);
            mLabelType = (TextView) view.findViewById(R.id.tv_label_title);
            mLabelData = (FlowLayout) view.findViewById(R.id.fl_label_data);
            tv_more = (TextView) view.findViewById(R.id.tv_more);

        }
    }
}
